package com.yan.service.impl;

import com.yan.entity.OrderDTO;
import com.yan.handler.AbstractHandler;
import com.yan.handler.HandlerContext;
import com.yan.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.stereotype.Component;

@ConditionalOnBean(HandlerContext.class)
@Component
public class OrderServiceImpl implements IOrderService {
    private final HandlerContext handlerContext;

    @Autowired
    public OrderServiceImpl(HandlerContext handlerContext) {
        this.handlerContext = handlerContext;
    }

    @Override
    public String handle(OrderDTO orderDTO) {
        AbstractHandler instance = handlerContext.getInstance(orderDTO.getCode());
        return instance.handle(orderDTO);
    }
}
